package com.topsun.posclient.system;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;

import com.topsun.posclient.common.util.SpringContextHolder;
import com.topsun.posclient.system.service.ISyncDataService;

public class SyncDataAction extends Action implements IWorkbenchAction {

	private ISyncDataService syncDataService = SpringContextHolder.getBean("syncDataService");
	
	private IWorkbenchWindow workbenchWindow;

	public SyncDataAction(IWorkbenchWindow window) {
		if (window == null) {
			throw new IllegalArgumentException();
		}
		this.workbenchWindow = window;
	}

	public void run() {
		if (workbenchWindow != null) {
			try {
				syncDataService.syncUserData();
			} catch (Exception e) {
		        MessageDialog.openError(workbenchWindow.getShell(), "Error", "Error in opening view :"+e.getLocalizedMessage());
			}
		}
	}

	public void dispose() {
		workbenchWindow = null;
	}

}
